﻿using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace CoinPriceTip
{
    public partial class Form1 : Form
    {
        private delegate void dltxt();
        private System.Timers.Timer t;
        private string curUrl = "https://www.jubi.com/coin/mryc/info.html";
        private double curPrice = 0.7;
        private double maxPrice = 0.73;
        public Form1()
        {
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern bool FlashWindow(IntPtr hWnd, bool bInvert);
        private void Form1_Load(object sender, EventArgs e)
        {
            webb.ScriptErrorsSuppressed = true;
            webb.Navigate(curUrl);
            t = new System.Timers.Timer(3000);//实例化Timer类，设置间隔时间为10000毫秒；
            t.Elapsed += new System.Timers.ElapsedEventHandler(readData);//到达时间的时候执行事件；
            t.AutoReset = true;//设置是执行一次（false）还是一直执行(true)；
            t.Enabled = true;
            t.Start();
        }

        private void readData(object source, System.Timers.ElapsedEventArgs e)
        {
            this.Invoke(new dltxt(setTxt));
        }
        private void setTxt()
        {
            String str = webb.Document.Body.OuterHtml;
            if (str.Length < 1) return;
            string s = "market-price";
            string a = str.Substring(str.IndexOf(s) + s.Length + 1);
            string b = a.Substring(0, a.IndexOf("<"));
            if (b.Length < 1) return;
            tb.Text = b;
            double mc = Convert.ToDouble(b);
            if (mc < curPrice)
            {
                curPrice -= 0.02;
                FlashWindow(this.Handle, false);
                MessageBox.Show("低价:" + mc.ToString());
            }
            else if (mc > maxPrice)
            {
                maxPrice += 0.05;
                FlashWindow(this.Handle, false);
                MessageBox.Show("高价");
            }
        }
    }
}
